﻿using System;
using ProjScan.Config;
using ProjScan.Modules;
using ProjScan.RecordManager;
using ProjScan.RecordManager.AssetData;
using ProjScan.ScanRule.Attr;
using ProjScan.Submodules.Art_Assets_Check;
using ProjScan.Tools;

namespace ProjScan.ScanRule.ArtAssets.Prefab
{
	// Token: 0x0200023F RID: 575
	[ArtAssetRuleAttr]
	internal class FaceTexDensityAvgTooSmall : RecordRuleImp<GameObjectAssetData, GameObjectRecordManager>
	{
		// Token: 0x06000F90 RID: 3984 RVA: 0x00044C00 File Offset: 0x00042E00
		public FaceTexDensityAvgTooSmall()
		{
			ArtAssetsCheckConfig artAssetsCheckConfig = Singleton<ConfigMgr>.Instance.GetConfig<ArtAssetsCheckConfig>() as ArtAssetsCheckConfig;
			this.minSqrtDensity = artAssetsCheckConfig.faceTexDensityMinSqrtDensity;
		}

		// Token: 0x06000F91 RID: 3985 RVA: 0x00044C3C File Offset: 0x00042E3C
		public override void CheckDirSetted()
		{
			bool separateDirSettingsEnabled = this.SeparateDirSettingsEnabled;
			if (separateDirSettingsEnabled)
			{
				bool flag = this.target_configs == null || this.target_configs.Length == 0;
				if (flag)
				{
					ScanLog.UnityLogError("美术资源检测规则 " + base.GetType().Name + " 执行失败，未设置目标文件夹");
				}
				bool flag2 = this.target_configs.Length == 1 && this.target_configs[0].assetPath.StartsWith("Assets/ArtCheckFolder");
				if (flag2)
				{
					ScanLog.UnityLogError("美术资源检测规则 " + base.GetType().Name + " 执行失败，未设置目标文件夹");
				}
			}
		}

		// Token: 0x06000F92 RID: 3986 RVA: 0x000403A4 File Offset: 0x0003E5A4
		public override bool CheckSupportability(out string msg)
		{
			msg = "";
			return true;
		}

		// Token: 0x06000F93 RID: 3987 RVA: 0x00044CE4 File Offset: 0x00042EE4
		protected override bool IsOK(GameObjectAssetData assetData)
		{
			float num = 0f;
			float num2 = 0f;
			bool flag = true;
			bool flag2 = assetData.averageDensity == "NULL" || string.IsNullOrEmpty(assetData.averageDensity);
			bool result;
			if (flag2)
			{
				try
				{
					ArtCheckCommonMethods.CheckUVDensity(assetData.linkedGameObject, ref num2, ref num);
					bool flag3 = flag;
					if (flag3)
					{
					}
					bool flag4 = string.IsNullOrEmpty(num2.ToString());
					if (flag4)
					{
						ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Art_Assets_Check, "RunFailed", "AverageDensity IsNullOrEmpty");
						flag = false;
					}
					bool flag5 = string.IsNullOrEmpty(num.ToString());
					if (flag5)
					{
						ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Art_Assets_Check, "RunFailed", "VarianceOfDensity IsNullOrEmpty");
						flag = false;
					}
				}
				catch (Exception exception_)
				{
					flag = false;
					ScanLog.Instance.LogException(exception_, "FaceTexDensityAvgTooSmall Run Failed", "RecordInfo: \n" + assetData.GetInfo() + "\n");
				}
				bool flag6 = flag;
				if (flag6)
				{
					assetData.averageDensity = num2.ToString();
					assetData.densityVariance = num.ToString();
					result = (num2 >= this.minSqrtDensity);
				}
				else
				{
					assetData.averageDensity = "FAILED";
					assetData.densityVariance = "FAILED";
					result = false;
				}
			}
			else
			{
				bool flag7 = assetData.averageDensity == "FAILED" || assetData.densityVariance == "FAILED";
				if (flag7)
				{
					ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Art_Assets_Check, "RunFailed", "Record field is FAILED");
					flag = false;
					result = false;
				}
				else
				{
					try
					{
						num2 = float.Parse(assetData.averageDensity);
					}
					catch (Exception exception_2)
					{
						flag = false;
						ScanLog.Instance.LogException(exception_2, string.Format("FaceTexDensityAvgTooSmall Run Failed( AverageDensity {0} )", num2), "RecordInfo: \n" + assetData.GetInfo() + "\n");
					}
					bool flag8 = num2.ToString() == "NaN";
					if (flag8)
					{
						flag = false;
						ScanLog.Instance.LogInfo(ScanLog.LogLevel.EXCEPTION, Module.Art_Assets_Check, "RunFailed", "Record field is NaN");
					}
					bool flag9 = flag;
					if (flag9)
					{
						result = (num2 >= this.minSqrtDensity);
					}
					else
					{
						assetData.averageDensity = "FAILED";
						assetData.densityVariance = "FAILED";
						result = false;
					}
				}
			}
			return result;
		}

		// Token: 0x04000902 RID: 2306
		private float minSqrtDensity = 128f;
	}
}
